<template>
  <div>
    <el-card shadow="always">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-select
            v-model="query.districtCode"
            placeholder="请选择区域"
            clearable
          >
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in [
                {
                  value: '吴中区',
                  label: '吴中区',
                },

                {
                  value: '相城区',
                  label: '相城区',
                },
                {
                  value: '高新区',
                  label: '高新区',
                },
                {
                  value: '姑苏区',
                  label: '姑苏区',
                },
                {
                  value: '工业园区',
                  label: '工业园区',
                },
                {
                  value: '常熟市',
                  label: '常熟市',
                },
                {
                  value: '张家港市',
                  label: '张家港市',
                },
                {
                  value: '昆山市',
                  label: '昆山市',
                },
                {
                  value: '吴江区',
                  label: '吴江区',
                },
                {
                  value: '太仓市',
                  label: '太仓市',
                },
                {
                  value: '张家港保税区',
                  label: '张家港保税区',
                },
              ]"
              :key="item.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-select
            v-model="query.certificationReport"
            placeholder="合格证明文件"
            clearable
          >
            <el-option
              v-for="item in [
                {
                  value: '1',
                  label: '是',
                },
                {
                  value: '0',
                  label: '否',
                },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-select
            v-model="query.quickInspection"
            placeholder="快检记录"
            clearable
          >
            <el-option
              v-for="item in [
                {
                  value: '1',
                  label: '是',
                },
                {
                  value: '0',
                  label: '否',
                },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.unitName"
            placeholder="请输入单位名称"
          ></el-input>
        </el-col>

        <el-col :span="2">
          <el-button
            type="primary"
            @click="
              getList();
              query.page = 1;
            "
            >查询</el-button
          ></el-col
        >

        <el-col :span="2">
          <el-button
            type="success"
            @click="
              addDistribution();
              query.page = 1;
            "
            >新增</el-button
          ></el-col
        >
        <!-- <el-col :span="2">
          <el-button type="default" @click="getExport">导出</el-button></el-col
        > -->
      </el-row>
      <rz-height></rz-height>

      <el-table border :data="tableData" style="width: 100%" stripe>
        <el-table-column
          label="区域"
          prop="districtCode"
          width="80"
        ></el-table-column>
        <el-table-column label="单位名称" prop="unitName"></el-table-column>

        <el-table-column label="单位地址" prop="unitAddress"></el-table-column>

        <el-table-column
          label="配送品种"
          prop="distributionVarieties"
        ></el-table-column>

        <el-table-column
          label="配送范围"
          prop="distributionScope"
        ></el-table-column>

        <el-table-column label="进货信息" prop="realNameBill">
          <template slot-scope="scope">
            <div class="green" v-if="scope.row.realNameBill === '1'">
              已对接上传进货信息
            </div>
            <div class="red" v-else>未对接上传进货信息</div>
          </template>
        </el-table-column>

        <el-table-column label="合格证明文件" prop="certificationReport">
          <template slot-scope="scope">
            <div class="green" v-if="scope.row.certificationReport === '1'">
              已对接上传合格证明文件
            </div>
            <div class="red" v-else>未对接上传合格证明文件</div>
          </template>
        </el-table-column>

        <el-table-column label="快检记录" prop="quickInspection">
          <template slot-scope="scope">
            <div class="green" v-if="scope.row.quickInspection === '1'">
              已对接上传快检记录
            </div>
            <div class="red" v-else>未对接上传快检记录</div>
          </template>
        </el-table-column>

        <el-table-column label="操作" prop="indexScore" width="220">
          <template slot-scope="scope">
            <el-button type="danger" size="mini" @click="del(scope.row)"
              >删除</el-button
            >
            <el-button size="mini" @click="view(scope.row)">查看</el-button>
            <el-button size="mini" @click="edit(scope.row)" type="primary"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        :page.sync="query.pageIndex"
        @pagination="getList"
        v-show="total"
      />
    </el-card>

    <el-dialog
      title="登录"
      :visible.sync="dialogVisible"
      width="400px"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <el-form ref="form" :model="form" label-width="0" :rules="rules">
        <el-form-item prop="mobile">
          <el-input
            v-model="form.mobile"
            maxlength="11"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="cipher">
          <el-input
            v-model="form.cipher"
            type="password"
            placeholder="请输入密码"
            maxlength="18"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit" style="width: 100%"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {
  findSupplierPromotionForm,
  deletesupplierPromotionForm,
  landSupplierPromotionForm,
} from "@/api/modules/enterprise";
import Vue from 'vue';
export default {
  // props:[],
  // 页面加载
  created() {
    // this.getList();
        if (this.$formValidate&&this.$formValidate.mobile) {
            this.dialogVisible = false;
          landSupplierPromotionForm({
            params: this.$formValidate,
          }).then((res) => {
            this.getList();
          
          });
        }
  },
  // 页面加载完成
  mounted() {},
  //实例销毁之前
  beforeDestroy() {},
  //实例销毁后
  destroyed() {},
  data() {
    return {
      query: {
        certificationReport: "",
        districtCode: "",
        pageIndex: 1,
        pageSize: 10,
        quickInspection: "",
        unitName: "",
      },
      tableData: [],
      total: 0,
      dialogVisible: true,
      form: {
        mobile: "",
        cipher: "",
      },
      rules: {
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        cipher: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  // 方法
  methods: {
    getList() {
         landSupplierPromotionForm({
            params: this.$formValidate,
          }).then((res) => {
      findSupplierPromotionForm(this.query).then((res) => {
        this.tableData = res.data.list;
        this.total = res.totalCount;
      });
      });
    },
    addDistribution() {
      this.$router.push("/addDistribution");
    },
    del(e) {
      this.$confirm("确认删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        landSupplierPromotionForm({
          params: this.$formValidate,
        }).then((res) => {
          deletesupplierPromotionForm({
            params: {
              id: e.id,
            },
          }).then((res) => {
            this.$success(res.msg);
            this.getList();
          });
        });
      });
    },
    view(e) {
      this.$router.push(`/viewDistribution?id=${e.id}`);
    },
    edit(e) {
      this.$router.push(`/addDistribution?id=${e.id}`);
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          landSupplierPromotionForm({
            params: this.form,
          }).then((res) => {
            this.$success(res.msg);
            Vue.prototype.$formValidate = this.form;
            this.getList();
            this.dialogVisible = false;
          });
        }
      });
    },
  },
  // 监听属性
  watch: {},
  // 组件
  components: {},
  // 计算属性
  computed: {},
};
</script>

<style lang="scss" scoped>
</style>